package tests;

import java.util.Hashtable;

public class Registry {

	private static Registry instance;
	
	protected Hashtable<String, Object> collection = new Hashtable<String, Object>();
	
	private Registry(){}
	
	public static Registry getInstance()
	{
		if (instance == null)
		{
			synchronized (Registry.class) {
				if (instance == null)
				{
					instance = new Registry();
				}	
			}
			
		}
		return instance;
	}
	
	public synchronized Object find(String what)
	{
		if (collection.containsKey(what)) return collection.get(what);
		else return false;
	}
	
	public synchronized boolean add(String name, Object element)
	{
		if (!collection.containsKey(name))
		{
			collection.put(name, element);
			return true;
		} else
		{
			return false;
		}
	}
	
	public synchronized int getSize()
	{
		return collection.size();
	}
	
	public synchronized void clean()
	{
		collection.clear();
	}
}
